﻿@model Backend.JYD.Model.Cust.CustMarketingInfo
@using Backend.JYD.Common;
@using Backend.JYD.Model.Cust;
@using Backend.JYD.Model.Task;
@{
    ViewBag.Title = "营销任务处理";
    Layout = "~/Views/Shared/_LayoutWin.cshtml";
    var stepModel = this.ViewBag.StepModel as TaskStepModel;
}
@using (Ajax.BeginForm("process", new { id = Model.MarketingId }, new AjaxOptions() { OnSuccess = "aftersave" }))
{
    @Html.ValidationSummary(true)
    <div class="ui_pop_body" style="width: 650px; height: 520px;">
        <div>
            <ul class="edit-ul">
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.CustNo)：</span>
                    <span class="s02">@Html.DisplayTextFor(model => model.CustNo)</span>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.CustName)：</span>
                    <span class="s02">@Html.DisplayTextFor(model => model.CustName)</span>
                </li>
            
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.ScheduleTime)：</span>
                    <span class="s02">@Html.DisplayTextFor(model => model.ScheduleTime)</span>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.ValidDays)：</span>
                    <span class="s02">@Html.DisplayTextFor(model => model.ValidDays)</span>
                </li>    
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.Memo)：</span>
                    <span class="s02">@Html.DisplayTextFor(model => model.Memo)</span>
                </li>    
                
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.TouchTime)：</span>
                    <span class="s02">
                    <input  type="text" name="TouchTime" id="TouchTime" value="@(Model == null || !Model.TouchTime.HasValue ? string.Empty : DateTimeHelper.GetDateShortFormat(Model.TouchTime.Value))"  onfocus="WdatePicker()" readonly="readonly" class="text-box single-line" data-val="true" data-val-required="实际接触时间 字段是必需的。" />
                    <img class="hand" onclick="WdatePicker({el:'TouchTime'})" src="/skin/datepicker/skin/datePicker.gif" width="16" height="22" align="absmiddle" />
                    </span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.TouchTime)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.Ways)：</span>
                    <span class="s02">@Html.EditorFor(model => model.Ways)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Ways)</i>
                </li>
                <li class="li01"  style="height:80px;">
                    <span class="s01">@Html.LabelFor(model => model.Remark)：</span>
                    <span class="s02">@Html.TextAreaFor(model => model.Remark, new { @rows = "5", style = "width:300px;" })</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Remark)</i>
                </li>                
            </ul>
            <ul class="edit-ul" style="display:none;margin-top:10px;" id="ulloop">
                <li class="li01">
                    <span class="s01"></span>
                    <span class="s02">下次营销计划</span>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.ScheduleTime)：</span>
                    <span class="s02">
                        <input  type="text" name="ScheduleTime" id="ScheduleTime" value="@(Model == null || !Model.ScheduleTime.HasValue ? string.Empty : DateTimeHelper.GetDateShortFormat(Model.ScheduleTime.Value))"  onfocus="WdatePicker()" readonly="readonly" class="text-box single-line" data-val="true" data-val-required="计划接触时间 字段是必需的。" />
                        <img class="hand" onclick="WdatePicker({el:'ScheduleTime'})" src="/skin/datepicker/skin/datePicker.gif" width="16" height="22" align="absmiddle" />
                    </span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.ScheduleTime)</i>
                </li>                
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.ValidDays)：</span>
                    <span class="s02">@Html.EditorFor(model => model.ValidDays)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.ValidDays)</i>
                </li>
                <li class="li01"  style="height:80px;">
                    <span class="s01">@Html.LabelFor(model => model.Memo)：</span>
                    <span class="s02">@Html.TextAreaFor(model => model.Memo, new { @rows = "5", style = "width:300px;" })</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Memo)</i>
                </li>
            </ul>
            <ul class="edit-ul" >
                <li class="li01">
                    <span class="s01"></span>
                    <span class="s02">
                        @if (stepModel == null)
                        {
                        <input type="submit" value="营销完成" onclick="return check(2)"/>
                        <input type="submit" value="完成并继续接触" onclick="return check(4)" style="display:none;" id="doloop"/>
                        <input type="button" value="下一次接触" onclick="checkandLoop()" id="donext"/>
                        <input type="submit" value="终止任务" onclick="return check(5)"/>
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(stepModel.NextStepIds))
                            { 
                        <input type="submit" value="营销完成" onclick="return check(2)"/>
                            }
                            if (stepModel.AllowLoop)
                            { 
                        <input type="submit" value="完成并继续接触" onclick="return check(4)" style="display:none;" id="doloop"/>
                        <input type="button" value="下一次接触" onclick="checkandLoop()"  id="donext"/>
                            }
                            if (stepModel.AllowStop)
                            {
                        <input type="submit" value="结束任务" onclick="return check(5)"/>
                            }
                        }
                        <input type="button" value="取消" onclick="closeWin()"/>
                        @Html.HiddenFor(model => model.MarketingId)
                        @Html.HiddenFor(model => model.TaskDetailId)
                        @Html.HiddenFor(model => model.TaskId)
                        @Html.HiddenFor(model => model.Status)
                    </span>
                </li>
            </ul>
        </div>
     </div>
    <script src="@Url.Content("~/skin/js/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="/skin/datepicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        function checkandLoop() {
            if (check(4)) {
                $("#ulloop").show();
                $("#doloop").show();
                $("#donext").hide();
                $("#ScheduleTime").val('');
                $("#ValidDays").val('');
                $("#Memo").val('');
            }
        }

        function aftersave(data) {
            if (data.code) {
                closeWinAndReload();
            }
            else {
                alert(data.msg);
            }
        }

        function check(idx) {
            $('#Status').val(idx);
            if (idx != 5) {
                var sdate = $('#TouchTime').val();
                if (!sdate) {
                    alert("请选择实际接触时间。");
                    return false;
                }
                else {
                    if (DateCompare("@DateTimeHelper.GetDateLongFormat(DateTime.Now)", sdate)) {
                        alert("实际接触时间，不能大于当前时间。");
                        return false;
                    }
                }
                if (!$('#Ways').val()) {
                    alert("请填写接触方式。");
                    return false;
                }
            }
            if (!$('#Remark').val()) {
                alert("请填写接触反馈。");
                return false;
            }

            return true;
        }

    </script>
}


